
package GUIs;

//author dimi

import javax.persistence.EntityManager;


public class Purchases_ProductsSelectionGUI extends javax.swing.JFrame {

    private EntityManager em;
    
    // Ορίζω ως γονέα τη φόρμα PurchasesGUI
    private PurchasesGUI parent;
    // Ορίζω τις φόρμες που θα ανοίγουν με τις επιλογές κουμπιών της 
    // Purchases_ProductsSelectionGUI 
    private Purchase_ShoppingCartGUI childForm1;
    
    public Purchases_ProductsSelectionGUI(PurchasesGUI parent, EntityManager em) {
        this.em = em;
        this.parent = parent;
        initComponents();
        setLocationRelativeTo(null); // Κεντράρει το παράθυρο στην οθόνη
    
    } // end of Purchases_ProductsSelectionGUI

   
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        Panel_Purchases_ProductSelection_Welcome = new javax.swing.JPanel();
        Label_Purchases_ProductSelection_Welcome = new javax.swing.JLabel();
        Button_Purchases_ProductSelection_Exit = new javax.swing.JButton();
        ScrollPane_Purchases_AvailableProducts = new javax.swing.JScrollPane();
        Table_Purchases_AvailableProducts = new javax.swing.JTable();
        Button_SelectProduct = new javax.swing.JButton();
        Button_MoveToCart = new javax.swing.JButton();
        Label_AvailableProducts = new javax.swing.JLabel();
        Label_SelectedProducts = new javax.swing.JLabel();
        ScrollPane_Purchases_SelectedProducts = new javax.swing.JScrollPane();
        Table_Purchases_SelectedProducts = new javax.swing.JTable();

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        Panel_Purchases_ProductSelection_Welcome.setBackground(new java.awt.Color(0, 153, 153));

        Label_Purchases_ProductSelection_Welcome.setBackground(new java.awt.Color(0, 153, 153));
        Label_Purchases_ProductSelection_Welcome.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Label_Purchases_ProductSelection_Welcome.setForeground(new java.awt.Color(153, 255, 255));
        Label_Purchases_ProductSelection_Welcome.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Label_Purchases_ProductSelection_Welcome.setText("ΑΓΟΡΕΣ - ΕΠΙΛΟΓΗ ΠΡΟΪΟΝΤΩΝ");

        javax.swing.GroupLayout Panel_Purchases_ProductSelection_WelcomeLayout = new javax.swing.GroupLayout(Panel_Purchases_ProductSelection_Welcome);
        Panel_Purchases_ProductSelection_Welcome.setLayout(Panel_Purchases_ProductSelection_WelcomeLayout);
        Panel_Purchases_ProductSelection_WelcomeLayout.setHorizontalGroup(
            Panel_Purchases_ProductSelection_WelcomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel_Purchases_ProductSelection_WelcomeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Label_Purchases_ProductSelection_Welcome, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        Panel_Purchases_ProductSelection_WelcomeLayout.setVerticalGroup(
            Panel_Purchases_ProductSelection_WelcomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Label_Purchases_ProductSelection_Welcome)
        );

        Button_Purchases_ProductSelection_Exit.setText("ΕΞΟΔΟΣ");
        Button_Purchases_ProductSelection_Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button_Purchases_ProductSelection_ExitActionPerformed(evt);
            }
        });

        Table_Purchases_AvailableProducts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        ScrollPane_Purchases_AvailableProducts.setViewportView(Table_Purchases_AvailableProducts);

        Button_SelectProduct.setBackground(new java.awt.Color(0, 153, 153));
        Button_SelectProduct.setForeground(new java.awt.Color(0, 102, 102));
        Button_SelectProduct.setText("Επιλογή Προϊόντος");

        Button_MoveToCart.setBackground(new java.awt.Color(0, 153, 153));
        Button_MoveToCart.setForeground(new java.awt.Color(0, 102, 102));
        Button_MoveToCart.setText("Μετάβαση στο Καλάθι Αγορών");
        Button_MoveToCart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button_MoveToCartActionPerformed(evt);
            }
        });

        Label_AvailableProducts.setText("Διαθέσιμα Προϊόντα Καταστήματος");

        Label_SelectedProducts.setText("Επιλεχθέντα Προϊόντα & Ποσότητά τους");

        Table_Purchases_SelectedProducts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        ScrollPane_Purchases_SelectedProducts.setViewportView(Table_Purchases_SelectedProducts);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Button_SelectProduct, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Button_MoveToCart)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(Button_Purchases_ProductSelection_Exit))
            .addComponent(Panel_Purchases_ProductSelection_Welcome, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Label_AvailableProducts)
                    .addComponent(ScrollPane_Purchases_AvailableProducts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Label_SelectedProducts, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(ScrollPane_Purchases_SelectedProducts)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(Panel_Purchases_ProductSelection_Welcome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Label_AvailableProducts)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ScrollPane_Purchases_AvailableProducts, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Label_SelectedProducts)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ScrollPane_Purchases_SelectedProducts, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Button_Purchases_ProductSelection_Exit)
                    .addComponent(Button_SelectProduct)
                    .addComponent(Button_MoveToCart)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Button_Purchases_ProductSelection_ExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button_Purchases_ProductSelection_ExitActionPerformed
        System.out.println("Επιλογή Εξόδου από τη φόρμα Επιλογής Προϊόντων");
        parent.setEnabled(true); // Ενεργοποιώ πάλι το παράθυρο της προηγούμενης φόρμας
        dispose();
    }//GEN-LAST:event_Button_Purchases_ProductSelection_ExitActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        System.out.println("Επιλογή Εξόδου από τη φόρμα Επιλογής Προϊόντων");
        parent.setEnabled(true); // Ενεργοποιώ πάλι το παράθυρο της προηγούμενης φόρμας
        dispose();

    }//GEN-LAST:event_formWindowClosing

    private void Button_MoveToCartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button_MoveToCartActionPerformed
        System.out.println("Επιλογή Μετάβασης στο Καλάθι");
        
        // Όταν επιλέξει ο χρήστης αυτό το κουμπί, εισερχόμαστε στη φόρμα 
        // Καλαθιού ShoppingCartGUI, που θέτουμε ως childForm1
        childForm1 = new Purchase_ShoppingCartGUI(this, em);
        
        // Ενεργοποιούμε το νέο παράθυρο Επιλογής Προϊόντων
        childForm1.setVisible(true);
        
        // Απενεργοποιούμε το τρέχον παράθυρο CustomerGUI
        setEnabled(false);
    }//GEN-LAST:event_Button_MoveToCartActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Button_MoveToCart;
    private javax.swing.JButton Button_Purchases_ProductSelection_Exit;
    private javax.swing.JButton Button_SelectProduct;
    private javax.swing.JLabel Label_AvailableProducts;
    private javax.swing.JLabel Label_Purchases_ProductSelection_Welcome;
    private javax.swing.JLabel Label_SelectedProducts;
    private javax.swing.JPanel Panel_Purchases_ProductSelection_Welcome;
    private javax.swing.JScrollPane ScrollPane_Purchases_AvailableProducts;
    private javax.swing.JScrollPane ScrollPane_Purchases_SelectedProducts;
    private javax.swing.JTable Table_Purchases_AvailableProducts;
    private javax.swing.JTable Table_Purchases_SelectedProducts;
    private javax.swing.JDialog jDialog1;
    // End of variables declaration//GEN-END:variables
}
